<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="login.LoginVo" %>
<%@ page import="org.apache.commons.mail.SimpleEmail" %>
<%@ page import="org.apache.commons.mail.EmailException" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>

<style>

#search_result_id{
	width: 500px;
	height: 350px;
	padding-top: 50px;
}

.se_id_res{
	width: 100px;
	height: 62px;
	color: white;
	font-size: 20px;
	font-weight: bold;
	background-color: #C90000;
	border:0.5px solid white;
	border-radius: 10px;
	margin-top: 50px;
	
}

#se_id_res_login{
	background-image: url('../images/searid_login.png');
	background-size:100% 100%;
	margin-right: 20px;
}

#se_id_res_home{
	background-image: url('../images/searid_home.png');
	background-size:100% 100%;
}

label{
	font-size: 30px;
	font-family: 'Nanum Gothic', sans-serif;
}
</style>

<body>
<jsp:useBean id="bean" class="login.Login"></jsp:useBean>
<jsp:setProperty property="*" name="bean"/>
<div id='search_result_id'>
<%
	LoginVo l = bean.search_pwd();
	if( l == null){
%>
	<script>
		alert("아이디가 존재하지 않거나, 입력하신 email이 다릅니다.");
		location.href='Main.jsp?inc_content=../login/search_pwd.jsp';
	</script>
	<%
		}else{
			String id_pwd = l.getPwd();
			String username = "Cold Eyes";
			String mailsubject = "Cold Eyes에서 보내드립니다.";
			String mailcontent = "당신의 비밀번호는 [ "+id_pwd+" ] 입니다";
			
			SimpleEmail email = new SimpleEmail(); // 선언을 한다
			email.setCharset("UTF-8");     // 인코딩을 설정한다.
			email.setHostName("smtp.gmail.com");
			email.setSmtpPort(456);
			email.setSSL(true);
			email.setTLS(true);

			email.setFrom("intotheji@gmail.com", username); //보내는 사람
			email.setAuthentication("intotheji", "dhqk8626"); //SMTP 인증 (보내는 사람 계정의 아이디와 패스워드)
			
			email.addTo(l.getEmail(), l.getMid()); //받는사람
			email.setSubject(mailsubject); //메일 제목
			email.setMsg(mailcontent); //메일 내용
			
			email.send(); //메일 발송
			
	%>
		<label>Send your password to email.</label><p/>
		<label>(written by James)</label><p/>
		
		<input type='button' id = 'se_id_res_login' class='se_id_res' onclick="location.href='Main.jsp?inc_content=../ColdEyes/log.jsp'">
		<input type='button' id = 'se_id_res_home' class='se_id_res' onclick="location.href='Main.jsp'">
	<%}%>

</div>
</body>
</html>